home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / alv.sun / alv.lha / src / p_event.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-08  |  7.6 KB  |  273 lines

  1. /********************************************** palette_event.c *********
  2.  *
  3.  *    Notes from  hsc%vanderbilt@csnet-relay
  4.  *    Date:    7/1/87
  5.  *
  6.  *    Based on the version provided by the SunMicrosystem, Inc., the
  7.  *    following features have been added to the palettetool:
  8.  *
  9.  *    1)    MS_RIGHT:    it paints the "selected color" over the
  10.  *                colors through to the color selected by RM.
  11.  *    2)    MS_MIDDLE:    this button reverses, or undoes, the last
  12.  *                RM.
  13.  *    3)    box lock:    the box is locked when the LM is pressed.
  14.  *                Another LM or MM/RM will unlock the lock.
  15.  *                This is intended to leave the box at the
  16.  *                color when the mouse is been moved to the
  17.  *                 control panel.  Caution: the user should
  18.  *                allow time to let the box catch up the
  19.  *                motion of the mouse, especially when the
  20.  *                mouse is moved from outside of the multiple-
  21.  *                canvas.
  22.  *    4)    single_canvas:  the layout of the single_canvas has been
  23.  *                changed to contain a colormap stripe reflecting
  24.  *                the current colormap setting. The motion of the
  25.  *                cursor within the single_canvas is traced by
  26.  *                an arrow pointing at the colormap entry the mouse
  27.  *                resides, together with the colormap entry number
  28.  *                displayed.  A RM will select that color and lock
  29.  *                the box at the corresponding color in the
  30.  *                multiple_canvas.  The user may then move the
  31.  *                mouse to the control panel and, if so wish,
  32.  *                change that color.  Pressing Reset button will
  33.  *                reset that color to its previous value before
  34.  *                the change.
  35.  */
  36. #include "p_include.h"
  37.  
  38.  
  39. oid
  40. isplay_event_proc(canvas, event, arg)
  41.     Canvas  canvas;
  42.     Event  *event;
  43.     caddr_t arg;
  44. {
  45.     int     pix;
  46.  
  47.     if (event_is_button(event)) {
  48.         pix = pw_get(canvas_pixwin(canvas), event_x(event), event_y(event));
  49.  
  50.         advance_arrow(pix);
  51.  
  52.         /*
  53.          * fake a notifier procedure call to draw a
  54.          * box over the corresponding color on the
  55.          * multiple_canvas
  56.          */
  57.         selected = FALSE;
  58.         event_set_id(event, LOC_MOVE);
  59.         event_set_x(event, (pix % 24) * (cwidth + xspace) + xoff);
  60.         event_set_y(event, (pix / 24) * (cheight + yspace) + yoff);
  61.         multiple_canvas_event_proc(multiple_canvas, event, arg);
  62.         /*
  63.          * fake another notifier procedure call to
  64.          * lock the box over the chosen color on
  65.          * the multiple_canvas
  66.          */
  67.         event_set_id(event, MS_LEFT);
  68.         multiple_canvas_event_proc(multiple_canvas, event, arg);
  69.     }
  70. }
  71.  
  72. oid
  73. ultiple_canvas_event_proc(m_canvas, event, arg)
  74.     Window  m_canvas;
  75.     Event  *event;
  76.     caddr_t arg;
  77. {
  78.     int     x, y, i, j, x0, x1, y0, y1, hx0, hx1, hy0, hy1;
  79.     int     in_a_box, in_a_new_box;
  80.     float   m, n;
  81.     Pixwin *pw;
  82.  
  83.     x = event_x(event);
  84.     y = event_y(event);
  85.  
  86.     m = (x - xoff) / (cwidth + xspace);
  87.     n = (y - yoff) / (cheight + yspace);
  88.     i = (int) m;
  89.     j = (int) n;
  90.  
  91.     pw = (Pixwin *) canvas_pixwin(m_canvas);
  92.  
  93.     /*
  94.      * trace the mouse motion and draw a box around the
  95.      * color panel pointed by the mouse brush trace is
  96.      * stopped when the LM is pressed, i.e., user has
  97.      * selected a color to modify and is on his way to
  98.      * the control panel (box sould not follow the
  99.      * mouse when it's on its way to the control panel)
  100.      */
  101.     if (event_id(event) == LOC_MOVE && !selected) {
  102.         x0 = xoff + i * (cwidth + xspace);
  103.         y0 = yoff + j * (cheight + yspace);
  104.         x1 = x0 + cwidth;
  105.         y1 = y0 + cheight;
  106.  
  107.         in_a_box = ((m - i) * (cwidth + xspace) <= cwidth &&
  108.                 (n - j) * (cheight + yspace) <= cheight &&
  109.                 i < 24 && j < 11);
  110.         in_a_new_box = (in_a_box && (i != hi || j != hj));
  111.  
  112.         if (in_a_new_box) {        /* inside a box */
  113.             if (hi >= 0) {        /* erase old box */
  114.                 hx0 = xoff + hi * (cwidth + xspace);
  115.                 hy0 = yoff + hj * (cheight + yspace);
  116.                 hx1 = hx0 + cwidth;
  117.                 hy1 = hy0 + cheight;
  118.                 draw_a_box(pw, hx0 - 3, hy0 - 3, hx1 + 3, hy1 + 3, BGCOLOR);
  119.             }
  120.             draw_a_box(pw, x0 - 3, y0 - 3, x1 + 3, y1 + 3, FGCOLOR);    /* draw new box */
  121.             advance_arrow(ijton(i, j));
  122.             hi = i;
  123.             hj = j;
  124.             highlighted = 1;
  125.         } else {            /* outside a box */
  126.             if (highlighted && (hi != i || hj != j) && hi >= 0) {
  127.                 hx0 = xoff + hi * (cwidth + xspace);
  128.                 hy0 = yoff + hj * (cheight + yspace);
  129.                 hx1 = hx0 + cwidth;
  130.                 hy1 = hy0 + cheight;
  131.                 draw_a_box(pw, hx0 - 3, hy0 - 3, hx1 + 3, hy1 + 3, BGCOLOR);
  132.                 advance_arrow(ijton(i, j));
  133.                 highlighted = 0;
  134.             }
  135.         }
  136.     }
  137.     /*
  138.      * when the LM is pressed, the mouse box is frozen
  139.      * at wherever it currently resides, so the user
  140.      * should allow time to let the box catch up the
  141.      * motion of the mouse, i.e., the box should
  142.      * confine the brush.
  143.      */
  144.     if (event_id(event) == MS_LEFT && event_is_down(event) && highlighted) {
  145.         selected = !selected;
  146.         selected_i = i;
  147.         selected_j = j;
  148.         selected_n = ijton(i, j);
  149.         panel_set_value(red_slider, r[selected_n]);
  150.         panel_set_value(green_slider, g[selected_n]);
  151.         panel_set_value(blue_slider, b[selected_n]);
  152.         old_r = r[selected_n];
  153.         old_g = g[selected_n];
  154.         old_b = b[selected_n];        /* save the overwritten
  155.                          * color for Reset */
  156.     }
  157.     /*
  158.      * right-mouse-paint undo procedure
  159.      */
  160.     if (event_id(event) == MS_MIDDLE && event_is_down(event)) {
  161.         unsigned tmp[3][MAX_CMAP_LEN];
  162.         int     i;
  163.  
  164.         selected = FALSE;
  165.         if (undo_len == 0) {
  166.             post_msg("Nothing to be undone");
  167.             return;
  168.         }
  169.         for (i = 0; i < undo_len; i++) {
  170.             tmp[0][i] = undo_r[i];
  171.             tmp[1][i] = undo_g[i];
  172.             tmp[2][i] = undo_b[i];
  173.             undo_r[i] = r[i + undo_start];
  174.             undo_g[i] = g[i + undo_start];
  175.             undo_b[i] = b[i + undo_start];
  176.             r[i + undo_start] = tmp[0][i];
  177.             g[i + undo_start] = tmp[1][i];
  178.             b[i + undo_start] = tmp[2][i];
  179.         }
  180.         put_colors(undo_start, undo_len + 1, &r[undo_start], &g[undo_start],
  181.                &b[undo_start]);
  182.     }
  183.     /*
  184.      * copy color from selected_n through to that
  185.      * pointed by the the right mouse button press
  186.      */
  187.     if (event_id(event) == MS_RIGHT && event_is_down(event)) {
  188.         int     n = ijton(i, j);
  189.  
  190.         selected = FALSE;
  191.         if (n >= 0 && n < MAX_CMAP_LEN && n != selected_n) {
  192.             int     i;
  193.  
  194.             if (event_ctrl_is_down(event)) {
  195.                 /*
  196.                  * paint the selected_n
  197.                  * color to pointed color
  198.                  */
  199.                 undo_start = n;
  200.                 undo_len = 1;
  201.             } else {
  202.                 /*
  203.                  * paint the selected_n
  204.                  * color through to pointed
  205.                  * color
  206.                  */
  207.                 undo_start = (n > selected_n) ? (selected_n + 1) : n;
  208.                 undo_len = abs(n - selected_n);
  209.             }
  210.  
  211.             /*
  212.              * save the overwitten part for
  213.              * undo
  214.              */
  215.             pw_setcmsname(pw, CMAP_NAME);
  216.             pw_getcolormap(pw, undo_start, undo_len, undo_r, undo_g, undo_b);
  217.  
  218.             /* do the right-mouse paint */
  219.             for (i = 0; i < undo_len; i++) {
  220.                 r[undo_start + i] = r[selected_n];
  221.                 g[undo_start + i] = g[selected_n];
  222.                 b[undo_start + i] = b[selected_n];
  223.             }
  224.             put_colors(undo_start, undo_len,
  225.                    &r[undo_start], &g[undo_start], &b[undo_start]);
  226.             post_msg("Colors copied from LM through to RM.  Press MM to undo");
  227.         }
  228.     }
  229. }
  230.  
  231.  
  232. oid
  233. ingle_canvas_event_proc(s_canvas, event, arg)
  234.     Window  s_canvas;
  235.     Event  *event;
  236.     caddr_t arg;
  237. {
  238.     int     y;
  239.     Pixwin *spw;
  240.  
  241.     if (event_id(event) == MS_MIDDLE && event_is_down(event)) {
  242.         selected = FALSE;
  243.         return;
  244.     }
  245.     y = (event_y(event) - bar_offset) / 3;
  246.     if (y >= MAX_CMAP_LEN || selected == TRUE)
  247.         return;
  248.     spw = canvas_pixwin(s_canvas);
  249.     entry_id(spw, y);
  250.     advance_arrow(y);
  251.     if (event_id(event) == MS_LEFT && event_is_down(event)) {
  252.         entry_id(spw, y);
  253.         advance_arrow(y);
  254.         /*
  255.          * fake a notifier procedure call to draw a
  256.          * box over the corresponding color on the
  257.          * multiple_canvas
  258.          */
  259.         selected = FALSE;
  260.         event_set_id(event, LOC_MOVE);
  261.         event_set_x(event, (y % 24) * (cwidth + xspace) + xoff);
  262.         event_set_y(event, (y / 24) * (cheight + yspace) + yoff);
  263.         multiple_canvas_event_proc(multiple_canvas, event, arg);
  264.         /*
  265.          * fake another notifier procedure call to
  266.          * lock the box over the chosen color on
  267.          * the multiple_canvas
  268.          */
  269.         event_set_id(event, MS_LEFT);
  270.         multiple_canvas_event_proc(multiple_canvas, event, arg);
  271.     }
  272. }
  273.